import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import React, { useState } from "react";
import SecondaryLayout from "../../../compoents/secondary-layout";
import classNames from "classnames";
import classes from "./nftTxnDetails.module.less";
import useServices from "../../../hooks/useRequest";
import { formateDate, getChainBrowser, getChainName, getMapFinalValue, getSpec } from "../../../utils";
import utilsFilters from "../../../utils/filters";
// import { utils } from "ethers";
import { POLLING_INTERVAL } from "../../../config";
import useCalculateAmount from "../../../hooks/useCalculateAmount";
import usePolling from "../../../hooks/usePolling";
import { useMount } from "ahooks";
import { getNFTRecordInfo } from "../../../api/wallet";
import toast from "../../../compoents/toast";
import { useTranslation } from "react-i18next";
import { LocalKeyMap } from "../../../local";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
// const handleTypeMap = {
//   "1": "DEPOSIT",
//   "2": "WITHDRAWAL",
// };
var NftTxnDetails = /*#__PURE__*/ React.forwardRef(function(props, ref) {
    var _useState = _sliced_to_array(useState(_object_spread({}, props)), 2), state = _useState[0], setState = _useState[1];
    var toFormatEther = useCalculateAmount().toFormatEther;
    var service = useServices({
        getNFTRecordInfo: getNFTRecordInfo
    });
    var t = useTranslation().t;
    var fetchDetail = function() {
        var _ref = _async_to_generator(function() {
            return _ts_generator(this, function(_state) {
                if (!props.id) return [
                    2
                ];
                service.getNFTRecordInfo(props.id).then(function(res) {
                    if (res.code !== 200) {
                        throw res;
                    }
                    if (res.code == 200 && res.data.status !== "active") {
                        setState(res.data);
                        props.handlerChangeStatus(res.data);
                        cancel === null || cancel === void 0 ? void 0 : cancel();
                    }
                }).catch(function(error) {
                    toast.createToast({
                        message: error.msg,
                        type: "errToast"
                    });
                });
                return [
                    2
                ];
            });
        });
        return function fetchDetail() {
            return _ref.apply(this, arguments);
        };
    }();
    var _usePolling = usePolling(fetchDetail, {
        pollingInterval: POLLING_INTERVAL,
        manual: true
    }), cancel = _usePolling.cancel, run = _usePolling.run;
    useMount(function() {
        if (props.status == "active") {
            run === null || run === void 0 ? void 0 : run();
        }
    });
    return /*#__PURE__*/ _jsx(SecondaryLayout, {
        backFn: props.backFn,
        ref: ref,
        className: classNames(props.className, classes.nft_txn_details),
        title: t(LocalKeyMap["nftHistoryDetails.title"]),
        children: /*#__PURE__*/ _jsxs("div", {
            className: classes.wrap,
            children: [
                /*#__PURE__*/ _jsxs("div", {
                    className: classes.info,
                    children: [
                        /*#__PURE__*/ _jsxs("div", {
                            className: classes.nft,
                            children: [
                                /*#__PURE__*/ _jsx("div", {
                                    className: classes.img,
                                    children: /*#__PURE__*/ _jsx("img", {
                                        // src={getNftImgSrc(state.tokenId || '', {
                                        //   chainType: state.chainType || '',
                                        //   contract: state.contract || '',
                                        // })}
                                        src: state.logoUrl
                                    })
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.basic,
                                    children: [
                                        /*#__PURE__*/ _jsx("div", {
                                            className: classes.name,
                                            children: state.name || "-"
                                        }),
                                        /*#__PURE__*/ _jsxs("div", {
                                            className: classes.tags,
                                            children: [
                                                /*#__PURE__*/ _jsx("div", {
                                                    className: classes.type,
                                                    children: state.type == "in" ? t(LocalKeyMap["nftHistory.tag.in"]) : t(LocalKeyMap["nftHistory.tag.to"]) || "-"
                                                }),
                                                state.handleType && /*#__PURE__*/ _jsx("div", {
                                                    className: classes.supple,
                                                    children: state.handleType == "INTERNAL" ? t(LocalKeyMap["nftHistory.tag.internal"]) : state.handleType == "IN_GAME" ? t(LocalKeyMap["nftHistory.tag.game"]) : ""
                                                })
                                            ]
                                        }),
                                        /*#__PURE__*/ _jsxs("div", {
                                            className: classes.gas,
                                            children: [
                                                /*#__PURE__*/ _jsxs("div", {
                                                    children: [
                                                        t(LocalKeyMap.transferFee),
                                                        ":"
                                                    ]
                                                }),
                                                /*#__PURE__*/ _jsx("div", {
                                                    className: classes.value,
                                                    children: "".concat(toFormatEther(state.gas || "0", {
                                                        contract: "n/a",
                                                        chainType: state.chainType
                                                    }))// ETHEREUM.includes(state.chainType || '') ? 'ETH' : 'BNB'
                                                    .concat(getMapFinalValue([
                                                        getChainName(state.chainType || "")
                                                    ], {
                                                        BSC: "BNB",
                                                        ETHEREUM: "ETH",
                                                        CONFLUX: "CFX"
                                                    }))
                                                })
                                            ]
                                        })
                                    ]
                                })
                            ]
                        }),
                        /*#__PURE__*/ _jsxs("div", {
                            className: classes.details,
                            children: [
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: state.type == "in" ? t(LocalKeyMap.from) : t(LocalKeyMap["nftHistoryDetails.to"])
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.value,
                                            children: utilsFilters.stringMethod((state.type == "in" ? state.from : state.to) || "")
                                        })
                                    ]
                                }),
                                state.handleType == "IN_GAME" && /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: t(LocalKeyMap.action)
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.value,
                                            children: state.handleStatus
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: t(LocalKeyMap.status)
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classNames(classes.value, state.status == "active" ? classes.padding : state.status == "success" ? classes.success : classes.failed),
                                            children: state.status == "active" ? t(LocalKeyMap["txn.status.padding"]) : state.status == "success" ? t(LocalKeyMap["txn.status.comfirmed"]) : t(LocalKeyMap["txn.status.failed"])
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: t(LocalKeyMap.date)
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.value,
                                            children: formateDate(state.transferTime || "")
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: t(LocalKeyMap.tokenStandard)
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.value,
                                            children: getSpec(state.chainType || "", state.spec || "")
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: t(LocalKeyMap.tokenID)
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.value,
                                            children: state.tokenId
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.desc,
                                    children: [
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.field,
                                            children: t(LocalKeyMap.tokenContract)
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.value,
                                            children: utilsFilters.stringMethod(state.contract || "-")
                                        })
                                    ]
                                })
                            ]
                        })
                    ]
                }),
                state.txHash && /*#__PURE__*/ _jsxs("div", {
                    className: classes.link,
                    onClick: function() {
                        // if (ETHEREUM.includes(state.chainType || '')) {
                        //   window.open(
                        //     `https://${isDevChain ? 'testnet.' : ''}etherscan.io/tx/${
                        //       state.txHash
                        //     }`,
                        //   );
                        // } else {
                        //   window.open(
                        //     `https://${isDevChain ? 'testnet.' : ''}bscscan.com/tx/${
                        //       state.txHash
                        //     }`,
                        //   );
                        // }
                        state.txHash && window.open(getChainBrowser(state.chainType || "", state.txHash));
                    },
                    children: [
                        /*#__PURE__*/ _jsx("img", {
                            src: require("../../../assets/icons/view.svg")
                        }),
                        /*#__PURE__*/ _jsxs("span", {
                            children: [
                                t(LocalKeyMap["nftHistoryDetails.view"]),
                                " ",
                                getMapFinalValue([
                                    getChainName(state.chainType || "")
                                ], {
                                    BSC: "BscScan",
                                    ETHEREUM: "etherscan",
                                    CONFLUX: "Confluxscan"
                                })
                            ]
                        })
                    ]
                })
            ]
        })
    });
});
export default NftTxnDetails;

 //# sourceMappingURL=index.js.map